/**
 * Jan 28, 2009
 * @author abhi.sanoujam
 */
package sample;

public class Counter {
  private final int numParties;
  private int value = 0;
  private final int maxValue;

  public Counter(int numParties, int maxValue) {
    this.numParties = numParties;
    this.maxValue = maxValue;
  }

  public synchronized boolean isMyTurn(int partyNum) {
    return value % numParties == partyNum;
  }

  public synchronized void setValue(int val) {
    this.value = val;
  }

  public int getMaxValue() {
    return maxValue;
  }

  public synchronized boolean isMaxValueReached() {
    return value >= maxValue;
  }

  public synchronized int increment() {
    this.value++;
    return value;
  }

  public synchronized int getValue() {
    return value;
  }
}